<?php
echo $this->Html->script(array(
	'lucky_draw',
	'player',
		), array('inline' => false));
$user = AuthComponent::user();
$isPlayable = !$user || ClassRegistry::init('UserReward')->isPlayable();
?>
<?php ?>
<div class="clearfix" style="padding: 0 1em;">
	<ul class="luckydraw-reward">
		<?php echo $output; ?>
	</ul>
	<div class="luckydraw-container clearfix">
		<div id="luckydraw">
			<canvas class="luckydraw-canvas" width="500" height="500"></canvas>
			<span class="luckydraw-cycle"></span>
			<span class="luckydraw-logo"></span>
		</div>
		<div class="luckydraw-control">
			<p class="item">
				<strong><?php echo __('Price'); ?> </strong>: <br/>
				<?php
				$condition = Configure::read('AppConfig.RewardPriceDescription');
				//echo str_replace(array("\t", "\r", "\n", "  ")
				//		, array('<span style="padding-left:10px"></span>', '', '<br/>', "&nbsp;")
					//	, $condition);
				?>
			</p>
			<?php if ($isPlayable) : ?>
				<p class="item">
					<?php if (!$user) : ?>
						<a class="luckydraw-login" href="<?php echo Router::url('/game/login'); ?>"><?php echo __('Login to play'); ?> </a>
					<?php else : ?>
						<a id="luckydraw-try" class="luckydraw-trigger" href="javascript:void(0);"><?php echo __('Try to play'); ?> </a>
					<?php endif; ?>
				</p>
				<p class="item">
					<?php if ($user) : ?>
						<a id="luckydraw-play" class="luckydraw-trigger" href="javascript:void(0);"><?php echo __('Play'); ?> </a>
					<?php endif; ?>
				</p>
			<?php else : ?>
				<p class="item">
					<a class="luckydraw-login" href="javascript:void(0);"><?php echo __('Game over'); ?> </a>
				</p>
			<?php endif ?>
		</div>
	</div>
</div>
<?php if ($isPlayable && $user) : ?>
	<div id="luckydraw-result" style="display: none;">
		<?php
		$dateFormat = Configure::read('AppConfig.RewardDateFormat');
		?>
		<dl style="margin:0;padding: 0;width: 600px;font-size:15px;">
			<dt style="margin:0;padding:0;">
			<?php echo __('Game result'); ?>
			</dt>
			<dd style="margin:0;padding:0;">
				<div style="background: #FFFFFF;margin: 0;padding: 10px 0 0 10px;">
					<div>
						<label style="width: 280px;display: inline-block;">
							<strong><?php echo __('Booking No.'); ?> : </strong>
							<?php echo $user['booking'] ?>
						</label>
						<label style="display: inline-block;">
							<strong><?php echo __('Date'); ?> : </strong>
							<?php echo date($dateFormat, time()) ?>
						</label>
					</div>
					<div>
						<label>
							<strong><?php echo __('Name'); ?> : </strong>
							<?php echo $user['last_name'] ?>
						</label>
					</div>
					<div>
						<label>
							<strong><?php echo __('First name'); ?> : </strong>
							<?php echo $user['first_name'] ?>
						</label>
					</div>
					<div>
						<label>
							<strong><?php echo __('Email'); ?> : </strong>
							<?php echo $user['email'] ?>
						</label>
					</div>
					<div>
						<label>
							<strong><?php echo __('Winning price'); ?> : </strong>
							<span id="luckydraw-winning"></span>
						</label>
					</div>
					<div>
						<label>
							<strong><?php echo __('Expiration date'); ?> : </strong>
							<?php echo date($dateFormat, time() + (Configure::read('AppConfig.RewardExpiredDay') * DAY)); ?>
						</label>
					</div>
					<div>
						<label>
							<strong><?php echo __('Condition'); ?> : </strong>
						</label>
						<div>
							<?php
							$condition = Configure::read('AppConfig.RewardCondition');
							echo str_replace(array("\t", "\r", "\n", "  ")
									, array('<span style="padding-left:10px"></span>', '', '<br/>', "&nbsp;")
									, $condition);
							?>
						</div>
					</div>
				</div>
				<p style="color: #555;">
					----------------------------------------------------------- <br />
					<?php echo __('Note that this result was made in two copies and sent simultaneously to the admin and custommer.'); ?> <br />
					<?php echo __('We will compare the results to the email received. If there is any wrong information, you will not receive the winning money.'); ?>
				</p>
			</dd>
		</dl>
	</div>
<?php endif; ?>
<script type="text/javascript">
	LuckyDrawOptions.segments = <?php echo json_encode($segments); ?>;
	LuckyDrawOptions.colors = <?php echo json_encode($colors); ?>;
	LuckyDrawOptions.url = <?php echo json_encode(Router::url('/game/play')); ?>;
</script>
<style type="text/css">
	#container{
		max-width: 900px;
		margin: 0 auto;
	}
</style>